/**
 * AbstractPieceOfProduct.java 21 juil. 07
 *
 * Copyright (c) 2007 windu.2b <jcaddie@windu2b.org>. All Rights Reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package org.windu2b.jcaddie.model;

import static org.windu2b.jcaddie.model.UserPreferences.*;

/**
 * @author windu.2b
 * 
 */
public class AbstractPieceOfProduct implements PieceOfProduct
{
	/**
	 * 
	 */
	private static final long	serialVersionUID	= 7387548134854816963L;


	protected String	      name;


	protected Content	      icon;


	protected Category	      category;


	protected float	          poids;


	protected float	          price;


	protected Unit	          unit;




	/**
	 * @param name
	 * @param icon
	 * @param category
	 * @param poids
	 * @param unit
	 */
	public AbstractPieceOfProduct( String name, Content icon,
	        Category category, float price, float poids, Unit unit )
	{
		this.name = name;
		this.icon = icon;
		this.category = category;
		this.price = price;
		this.poids = poids;
		this.unit = unit;
	}




	public String toString()
	{
		return name;
	}




	/**
	 * @param icon
	 *            the icon to set
	 */
	public void setIcon( Content icon )
	{
		this.icon = icon;
	}




	/**
	 * @param name
	 *            the name to set
	 */
	public void setName( String name )
	{
		this.name = name;
	}




	/**
	 * @param poids
	 *            the poids to set
	 */
	public void setPoids( float poids )
	{
		this.poids = poids;
	}




	/**
	 * @return the icon
	 */
	public Content getIcon()
	{
		return icon;
	}




	/**
	 * @return le nom du produit
	 */
	public String getName()
	{
		return name;
	}




	/**
	 * @return le poids du produit
	 */
	public float getPoids()
	{
		return poids;
	}




	/**
	 * @return le prix du produit
	 */
	public float getPrice()
	{
		return price;
	}




	/**
	 * @return la <code>Category</code> dans laquelle le produit se classe
	 */
	public Category getCategory()
	{
		return category;
	}




	/**
	 * @param category
	 *            la <code>Category</code> dans laquelle le produit se classe
	 */
	public void setCategory( Category category )
	{
		this.category = category;
	}




	/**
	 * @param price
	 *            Le nouveau prix du produit
	 */
	public void setPrice( float price )
	{
		//TODO Permettre d'archiver l'ancien prix, afin de pouvoir ensuite comparer l'évolution d'un prix
		this.price = price;
	}




	/**
	 * @return l'unité utilisée pour définir la quantité du produit
	 */
	public Unit getUnit()
	{
		return unit;
	}




	/**
	 * @return le prix du produit, au kilo, au litre ou à la pièce (selon l'unité)
	 */
	public float getUnitPrice()
	{
		return price / poids;
	}




	@Override
	public boolean equals( Object obj )
	{
		return obj instanceof AbstractPieceOfProduct
		        && ( ( AbstractPieceOfProduct ) obj ).category
		                .equals( category )
		        && ( ( AbstractPieceOfProduct ) obj ).name.equals( name )
		        && ( ( AbstractPieceOfProduct ) obj ).poids == poids
		        && ( ( AbstractPieceOfProduct ) obj ).price == price;
	}




	public int hashCode()
	{
		return super.hashCode();
		/*
		 * return category.hashCode() + name.hashCode() + new Float( poids
		 * ).hashCode() + new Float( price ).hashCode();
		 */
	}
}
